package base.utils

import android.app.NotificationManager
import android.content.Context
import androidx.core.app.NotificationCompat
import base.sys.DOWNLOAD_NOTIFICATION_ID

/**
 * Created by Administrator on 2017/11/6.
 */

class DownNotification(private val mContext: Context) {
    private var mBuilder: NotificationCompat.Builder? = null
    private var mNotifyManager: NotificationManager? = null
    private val id: Int

    init {
        id = DOWNLOAD_NOTIFICATION_ID
    }

    fun init(title: String, contentText: String, iconId: Int): DownNotification {
        mNotifyManager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        mBuilder = NotificationCompat.Builder(mContext)
        mBuilder!!.setContentTitle(title)
                .setContentText(contentText)
                .setSmallIcon(iconId)
        return this
    }

    fun setProgress(max: Int, progress: Int, indeterminate: Boolean): DownNotification {
        mBuilder!!.setProgress(max, progress, indeterminate)
        mNotifyManager!!.notify(id, mBuilder!!.build())
        return this
    }

    fun setProgressComplete(completeText: String): DownNotification {
        mBuilder!!.setContentText(completeText).setProgress(0, 0, false)
        mNotifyManager!!.notify(id, mBuilder!!.build())
        return this
    }

    fun cancel() {
        mNotifyManager!!.cancel(id)
    }

    fun getmBuilder(): NotificationCompat.Builder? {
        return mBuilder
    }

    companion object {

        private val TAG = "DownNotification"
    }
}